$(function(){
    sideNavFocusColor();
    displayTime();
});

//侧边导航选中变色
function sideNavFocusColor(){
    $(".side-nav-item").click(function(){
        $(".side-nav-item").eq($(this).index()).addClass("side-nav-active").siblings().removeClass("side-nav-active");
    });
}
//获取当前时间
function displayTime() {
    var myDate = new Date();
    var year=myDate.getFullYear();
    var month=myDate.getMonth()+1;
    var date=myDate.getDate();
    var h=myDate.getHours();
    var m=myDate.getMinutes();
    var s=myDate.getSeconds();

    var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m)+":"+p(s);
    $("#present-time").html(now);
    //刷新时间
    setTimeout("displayTime()",1000);
    //时间格式：小于10，用0填充
    function p(s) {
        return s < 10 ? '0' + s: s;
    }
}

//获取用户信息
// 根据不同的角色展示不同的菜单
var vm = new Vue({
    el: 'nav,#side-nav',
    data:{
        roleId: 5,
        username: "",
        homeUrl: ""
    },
    beforeMount: function () {
        $.ajax({
            type: "get",
            url: "../user/myInfo",
            headers: {"Token": sessionStorage.Token},
            dataType: "json",
            success: function(result){
                if(result.data.roleId != undefined){
                    vm.roleId = result.data.roleId;
                    sessionStorage.roleId = result.data.roleId;
                    vm.username = result.data.username;
                    if(vm.roleId <= 2){
                        vm.homeUrl = "home/admin-home.html";
                    }
                    else {
                        vm.homeUrl = "home/user-home.html";
                    }
                }
            }
        });
    },
});